//
//  MineTableViewController.m
//  EasyToTesco2.0
//
//  Created by 杨森 on 16/5/30.
//  Copyright © 2016年 EasyToTesco. All rights reserved.
//

#import "MineTableViewController.h"
#import "MineHeaderView.h"
#import "MineFirstCell.h"
#import "MineSecondCell.h"
#import "MyAccountTableViewController.h"
#import "AccountSetupController.h"
#import "BaseNavigationController.h"
#import "LogInViewController.h"
#import "SetupController.h"
#import "MyStandingsViewController.h"
#import "IndividualTableViewController.h"
#import "SellerPreFectureTableViewController.h"
#import "SetupController.h"
#import "SuggestionsController.h"
#import "MyAssertViewCell.h"
#import "MyCollectionController.h"
#import "ShareEasyViewController.h"
#import "TourOrderViewController.h"


//我的订单
#import "GoodsOrderViewController.h"
#import "OilOrderViewController.h"
#import "CoastOrderViewController.h"
#import "RechargeRecordController.h"


#import "PayMoneyController.h"
#import "ActivityRecordController.h"
#import "QR_CodeViewController.h"
#import "inviteQRCodeController.h"
#import "MineMenuTableViewCell.h"
#import "UITabBar+badge.h"
#import "ChatListViewController.h"
#import "ChatDemoHelper.h"
#import "ChatListViewController.h"

#import "ExtensionSystemController.h"
#import "CommissionRunController.h"
#import "QRCodeScanningViewController.h"

/**
 *  判断个人或商家专区
 */
#define JudgeInvididualOrSeller ([ReadLoginData readLoginData].allKeys.count == 0)||([[[ReadLoginData readLoginData] objectForKey:@"lb"] isEqualToString:@"0"])||([[[ReadLoginData readLoginData] objectForKey:@"lb"] isEqualToString:@"1"])

@interface MineTableViewController ()<MineHeaderViewDelegate,MineSecondCellDelegate,UIAlertViewDelegate,MyAssertViewCellDelegate,MineMenuTableViewCellDelegate>
{
    NSArray *mineArr;
    NSString *userNameString;
}
@property (nonatomic,strong)NSDictionary *userInfoDict;

@property (nonatomic,strong)MineHeaderView *headView;
@end

@implementation MineTableViewController

/**
 *  提交测试
 */
static NSString *const mineFirstId = @"mineFirstId";

- (void)loadView {
    [super loadView];
    
    if (JudgeLogInData) {
        [self loadUserInfoNumberData];
    }
}

- (void)setUnReadCount {
    NSArray *conversations = [[EMClient sharedClient].chatManager getAllConversations];
    NSInteger unreadCount = 0;
    for (EMConversation *conversation in conversations) {
        unreadCount += conversation.unreadMessagesCount;
    }
    if (unreadCount > 0) {
        
        [self.tabBarController.tabBar showBadgeOnItemIndex:4];
        
    }else{
        [self.tabBarController.tabBar hideBadgeOnItemIndex:4];
    }
    NSLog(@"%ld",(long)unreadCount);
}


- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self setHidesBottomBarWhenPushed:NO];
    if (JudgeLogInData) {
        NSLog(@"%@",[ReadLoginData readLoginData]);
        [self loadUserInfoNumberData];
    } else {
        [self.tableView reloadData];
    }
    
    if ([ChatDemoHelper setUnReadMessageCount] > 0) {
        [self.tabBarController.tabBar showBadgeOnItemIndex:4];
    } else {
        [self.tabBarController.tabBar hideBadgeOnItemIndex:4];
    }
    
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        
        [self.tableView setSeparatorInset:UIEdgeInsetsMake(0, -25, 0, 0)];
        
    }
    
    [self.navigationController setNavigationBarHidden:YES animated:animated];
 
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.edgesForExtendedLayout = UIRectEdgeNone;
    mineArr = @[@"我的亿乐账户",@"我的代金券",@"活动记录",@"个人专区",@"我的收藏",@"意见反馈"];
    self.tableView.showsVerticalScrollIndicator = NO;
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadTableView) name:@"ReloadMineTableView" object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reload) name:@"reload" object:nil];
}

- (void)reload {
    [self.tableView reloadData];
}

- (void)reloadTableView {
    [self.tableView reloadData];
    if (![ChatDemoHelper setUnReadMessageCount]) {
        [self.tabBarController.tabBar hideBadgeOnItemIndex:4];
    }
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"ReloadMineTableView" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"reload" object:nil];
}

#pragma mark>>>>>>>>>>>数据源
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 2;
    }else if (section == 1){
        return 2;
    }else{
        return 2;
    }
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    

    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"aaaa"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"aaaa"];
        cell.textLabel.font = FONT(15);
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    
    
    if (indexPath.section == 0) {
        
        if (indexPath.row == 0) {
            
        
            MineFirstCell *cell = [tableView dequeueReusableCellWithIdentifier:mineFirstId];
        
            if (cell==nil) {
        
                cell = [[MineFirstCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:mineFirstId];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                cell.textLabel.textColor = [UIColor blackColor];
                
            }
            cell.mineLabel.text = @"我的资产";
           
            //充值
            [cell.PayBtn setTitle:@"充值" forState:UIControlStateNormal];
            cell.PayBtn.titleLabel.font = FONT(15);
            [cell.PayBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [cell.PayBtn setImage:[UIImage imageNamed:@"icon_PayBtn"] forState:UIControlStateNormal];
//            cell.PayBtn.contentMode = UIViewContentModeCenter;
            cell.PayBtn.imageEdgeInsets = UIEdgeInsetsMake(0,-20,0,0);
            [cell.PayBtn addTarget:self action:@selector(payBtnDidClick) forControlEvents:UIControlEventTouchUpInside];
            
            return cell;
        }else{
        
            MyAssertViewCell *cell = [[MyAssertViewCell alloc] init];
            cell.delegate = self;
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            if (JudgeLogInData && self.userInfoDict != 0) {
                cell.userInfoNumberData = self.userInfoDict;
            }
            cell.logInDic = [ReadLoginData readLoginData];
            return cell;

        }
    
    } else if(indexPath.section == 1 ){
        
        if (indexPath.row == 0) {
            MineFirstCell *cell = [tableView dequeueReusableCellWithIdentifier:mineFirstId];
            
            if (cell==nil) {
                
                cell = [[MineFirstCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:mineFirstId];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                cell.textLabel.textColor = [UIColor blackColor];
                
            }
            cell.mineLabel.text = @"我的订单";
            
            [cell.PayBtn setTitle:@"付款" forState:UIControlStateNormal];
            cell.PayBtn.titleLabel.font = FONT(15);
            [cell.PayBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            
            cell.PayBtn.imageEdgeInsets = UIEdgeInsetsMake(0,-20,0,0);
            cell.payButtonBlock = ^(){
            
                if(JudgeInvididualOrSeller) {
                    //用户是否登录
                    [self judgeUser];

                    [self pushQRCodeScanning];
                } else {
                    //用户是否登录
                    [self judgeUser];
                    [self businessQR_CodeDidClick];
                }
            
            };
            
            if (JudgeInvididualOrSeller) {
                [cell.PayBtn setTitle:@"付款" forState:UIControlStateNormal];
                [cell.PayBtn setImage:[UIImage imageNamed:@"转账"] forState:UIControlStateNormal];
            } else {
                [cell.PayBtn setImage:[UIImage imageNamed:@"二维码"] forState:UIControlStateNormal];
                [cell.PayBtn setTitle:@"收款码" forState:UIControlStateNormal];
            }
        
            return cell;
            
        }else{
            MineSecondCell *cell = [[MineSecondCell alloc] init];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.delegate = self;
            return cell;
        }

    }else {
        
        if (indexPath.row == 0) {

            cell.textLabel.text = @"我的账户";
            cell.accessoryType = UITableViewCellAccessoryNone;
            return cell;

        } else {
            
            MineMenuTableViewCell *last = [tableView dequeueReusableCellWithIdentifier:@"menu"];
            if (!last) {
                last = [[MineMenuTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"menu"];
                last.selectionStyle = UITableViewCellSelectionStyleNone;
            }
            if (JudgeInvididualOrSeller) {
                last.titleLabel.text = @"个人专区";
                last.lastImageView.hidden = NO;
                last.lastLabel.hidden = NO;
            } else {
                last.titleLabel.text = @"商家专区";
                last.lastLabel.hidden = false;
                last.lastImageView.hidden = false;
            }
            last.delegate = self;
            
            if ([ChatDemoHelper setUnReadMessageCount] > 0) {
                last.unReadLabel.hidden = NO;
                last.unReadLabel.text = [NSString stringWithFormat:@"%ld",[ChatDemoHelper setUnReadMessageCount]];
            } else {
                last.unReadLabel.hidden = YES;
                last.unReadLabel.text = nil;
            }
            
            if (![ReadLoginData readLoginData].count) {
                last.unReadLabel.hidden = YES;
                last.unReadLabel.text = nil;
            }
            
            return last;
        }
    }
}


#pragma mark>>>>>>>>>>>>代理
- (void)MineMenuTableViewCellDidSelectedAtIndex:(NSInteger)index {
    
//    if (([ReadLoginData readLoginData].allKeys.count != 0) && ([[[ReadLoginData readLoginData] objectForKey:@"lb"] isEqualToString:@"4"])) {
//        if (index == 17) {
//            return;
//        }
//    }
    
    if ([JudgeUserLogInTool JudgeUserLonInStatus:self.view]) {
     
        switch (index) {
            case 10:
            {
                // 我的亿乐账户
                MyAccountTableViewController *myAccount = [[MyAccountTableViewController alloc] init];
                myAccount.userNameString = [self.userInfoDict[@"data"] objectForKey:@"xingming"];
                [self.navigationController pushForm:self.navigationController pushToAndHidden:myAccount];
                
            }
                break;
                
            case 11:
            {
                //我的积分
                MyStandingsViewController *myStandings = [[MyStandingsViewController alloc] init];
                if (JudgeInvididualOrSeller) {
                    myStandings.title = @"代金券详情";
                } else {
                    myStandings.title = @"让利金详情";
                }
                myStandings.nameLabelString = [self.userInfoDict[@"data"] objectForKey:@"xingming"];
                [self.navigationController pushForm:self.navigationController pushToAndHidden:myStandings];
            }
                break;
                
            case 12:
            {
                //活动记录
                ActivityRecordController *ActivityRecordVC = [[ActivityRecordController alloc] init];
                ActivityRecordVC.title = @"活动记录";
                [self.navigationController pushForm:self.navigationController pushToAndHidden:ActivityRecordVC];
            }
                break;
                
            case 13:
            {
#warning 商家个人专区却换
                if (JudgeInvididualOrSeller) {
                    //个人专区
                    IndividualTableViewController *individual = [[IndividualTableViewController alloc] init];
                    
                    if (self.userInfoDict) {
                        //充值账户传值
                        individual.voucherStr = self.userInfoDict[@"zongjifen"];
                    }
                    
                    [self.navigationController pushForm:self.navigationController pushToAndHidden:individual];
                } else {
                    //商家专区
                    SellerPreFectureTableViewController *seller = [[SellerPreFectureTableViewController alloc] init];
                    
                    if (self.userInfoDict) {
                        //充值账户传值
                        seller.cashStr = self.userInfoDict[@"yue"];
                    }
                    [self.navigationController pushForm:self.navigationController pushToAndHidden:seller];
                }
            }
                break;
                
            case 14:
                NSLog(@"聊天列表");
            {
                ChatListViewController *list = [[ChatListViewController alloc] init];
                list.title = @"聊天列表";
                [self.navigationController pushForm:self.navigationController pushToAndHidden:list];
            }

                break;
                
            case 15:
                
                
            {
                
                //我的收藏
                MyCollectionController *MyCollectionVC = [[MyCollectionController alloc] init];
                MyCollectionVC.title = @"我的收藏";
                [self.navigationController pushForm:self.navigationController pushToAndHidden:MyCollectionVC];
            }
                break;
                
            case 16:
            {
                
                //分享亿乐
                ShareEasyViewController *shareVC = [[ShareEasyViewController alloc] init];
                [self.navigationController pushForm:self.navigationController pushToAndHidden:shareVC];
            }
                break;
                
            case 17:
            {
                ExtensionSystemController *extensionVC = [[ExtensionSystemController alloc] init];
                [self.navigationController pushForm:self.navigationController pushToAndHidden:extensionVC];
            }
                break;
                
            default:
                break;
        }
    } else {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"您尚未登录用户" message:nil preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *SettingAction = [UIAlertAction actionWithTitle:@"去登录" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            LogInViewController *accountVC = [[LogInViewController alloc] init];
            UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:accountVC];
            [self presentViewController:nav animated:YES completion:nil];
        }];
        [alert addAction:SettingAction];
        
        
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消"style:UIAlertActionStyleCancel handler:nil];
        [alert addAction:cancelAction];
        
        [self presentViewController:alert animated:YES completion:nil];
    }
}

-(void)didSelectedSwitchViewController:(UITableViewController *)controller
{
    UITableViewController *VC = [[UITableViewController alloc] init];
    VC = controller;
    [self.navigationController pushForm:self.navigationController pushToAndHidden:controller];
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        
        if (indexPath.row == 0) {
            return HEIGHT/14;
        }else{
            return HEIGHT/10;
        }
        
    }else if(indexPath.section == 1){
        
        if (indexPath.row == 0) {
            return HEIGHT/14;
        }else{
            return HEIGHT/10;
        }
    }else{
        if (indexPath.row == 0) {
            return HEIGHT/14;
        } else {
            return HEIGHT/4;
        }
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return HEIGHT/5;
    }
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}

- ( UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        MineHeaderView *headView = [[MineHeaderView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT/5)];
        headView.delegate = self;
        self.headView = headView;
        headView.leftBtnBlcok = ^() {
            //用户是否登录
            [self judgeUser];

            [self pushQRCodeScanning];
        };
        return headView;
    }
    return nil;
}

- (void)pushQRCodeScanning {
    // 1、 获取摄像设备
    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    if (device) {
        AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
        if (status == AVAuthorizationStatusNotDetermined) {
            [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
                if (granted) {
                    dispatch_async(dispatch_get_main_queue(), ^{
                        QRCodeScanningViewController *vc = [[QRCodeScanningViewController alloc] init];
                        [self.navigationController pushForm:self.navigationController pushToAndHidden:vc];
                    });
                    
                    SGQRCodeLog(@"当前线程 - - %@", [NSThread currentThread]);
                    // 用户第一次同意了访问相机权限
                    SGQRCodeLog(@"用户第一次同意了访问相机权限");
                    
                } else {
                    
                    // 用户第一次拒绝了访问相机权限
                    SGQRCodeLog(@"用户第一次拒绝了访问相机权限");
                }
            }];
        } else if (status == AVAuthorizationStatusAuthorized) { // 用户允许当前应用访问相机
            QRCodeScanningViewController *vc = [[QRCodeScanningViewController alloc] init];
            [self.navigationController pushForm:self.navigationController pushToAndHidden:vc];
        } else if (status == AVAuthorizationStatusDenied) { // 用户拒绝当前应用访问相机
            UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"⚠️ 警告" message:@"请去-> [设置 - 隐私 - 相机 - SGQRCodeExample] 打开访问开关" preferredStyle:(UIAlertControllerStyleAlert)];
            UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
                
            }];
            
            [alertC addAction:alertA];
            [self presentViewController:alertC animated:YES completion:nil];
            
        } else if (status == AVAuthorizationStatusRestricted) {
            NSLog(@"因为系统原因, 无法访问相册");
        }
    } else {
        UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"未检测到您的摄像头" preferredStyle:(UIAlertControllerStyleAlert)];
        UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        
        [alertC addAction:alertA];
        [self presentViewController:alertC animated:YES completion:nil];
    }
}

#pragma mark >>>>>>>>>>>头部视图代理方法
- (void)mineHeaderDidClick
{
    if ([ReadLoginData readLoginData].count != 0) {
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"退出用户登录" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
        
        alert.tag = 1001;
        
        [alert show];
        
    } else {
        LogInViewController *accountVC = [[LogInViewController alloc] init];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:accountVC];
        [self presentViewController:nav animated:YES completion:nil];

    }
    
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (alertView.tag == 1001) {
        if (buttonIndex == 0) {
            [ReadLoginData cleanloginData];
            [ReadLoginData logoutAction:self.view];
            [self.tableView reloadData];
        }
    }
}

#pragma mark 设置
- (void)mineHeaderSetupDidClick
{
    SetupController *setupVc = [[SetupController alloc] init];
    [self.navigationController pushForm:self.navigationController pushToAndHidden:setupVc];
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
    NSLog(@"%f",self.tableView.y);
}

#pragma mark 充值
- (void)payBtnDidClick
{   //用户是否登录
    [self judgeUser];
    
    PayMoneyController *PayMoneyVC = [[PayMoneyController alloc] init];
    [self.navigationController pushForm:self.navigationController pushToAndHidden:PayMoneyVC];
}

#pragma mark 二维码收款
- (void)businessQR_CodeDidClick
{
    //用户是否登录
    [self judgeUser];
    
    NSLog(@"商家");
    
    QR_CodeViewController *inviteVC = [[QR_CodeViewController alloc] init];
    [self.navigationController pushForm:self.navigationController pushToAndHidden:inviteVC];
    
}

#pragma mark >>>>>>>>>>>我的订单delegate
- (void)mineSecondCellDidClickIndex:(NSInteger)index
{
    NSLog(@"%ld",index);
    
    //用户是否登录
    [self judgeUser];

    if (index == 100) {
        //商品
        GoodsOrderViewController *GoodsOrderVC = [[GoodsOrderViewController alloc] init];
        [self.navigationController pushForm:self.navigationController pushToAndHidden:GoodsOrderVC];
        
    }else if (index == 101){
        //加油卡
        OilOrderViewController *OilOrderVC = [[OilOrderViewController alloc] init];
        [self.navigationController pushForm:self.navigationController pushToAndHidden:OilOrderVC];
        
    }else if (index == 102){
        //话费
        CoastOrderViewController *CoastOrderVC = [[CoastOrderViewController alloc] init];
        [self.navigationController pushForm:self.navigationController pushToAndHidden:CoastOrderVC];
        
    }else if (index == 103) {
        //充值记录
        RechargeRecordController *RechargeRecordVC = [[RechargeRecordController alloc] init];
        RechargeRecordVC.title = @"充值记录";
        [self.navigationController pushForm:self.navigationController pushToAndHidden:RechargeRecordVC];
    } else {
        TourOrderViewController *tour = [[TourOrderViewController alloc] init];
        [self.navigationController pushForm:self.navigationController pushToAndHidden:tour];
    }

    
}



#pragma mark >>>>>>>>>>> 我的资产delegate
- (void)assertViewDidClick:(UIButton *)button
{

    [self judgeUser];
    if (button.tag == 1992) {
        //充值账户
        NSLog(@"充值账户");
        
    }else if (button.tag == 1993){
        //积分余额
        MyStandingsViewController *myStandings = [[MyStandingsViewController alloc] init];
        myStandings.nameLabelString = [self.userInfoDict[@"data"] objectForKey:@"xingming"];
        if (JudgeInvididualOrSeller) {
            myStandings.title = @"代金券详情";
        } else {
            myStandings.title = @"让利金详情";
        }
        [self.navigationController pushForm:self.navigationController pushToAndHidden:myStandings];
        
    }else if (button.tag == 1994){
        //总消费额
        NSLog(@"总消费");
        
    }else{
        if (JudgeInvididualOrSeller) {
            CommissionRunController *commision = [[CommissionRunController alloc] init];
            [self.navigationController pushForm:self.navigationController pushToAndHidden:commision];
        } else {
            return;
        }
    }
}

- (NSDictionary *)userInfoDict {
    if (!_userInfoDict) {
        _userInfoDict = [NSDictionary dictionary];
    }
    return _userInfoDict;
}

- (void)loadUserInfoNumberData {
    
    NSDictionary *params = @{
                             @"username":USERNAME
                             };
    
    [[NetWorkSharedTools sharedNetWorkTools] objectWithURLDict:params AndMenthodName:@"api/User/info" completeBlock:^(id object) {
        
        if (JudgeLogInData) {
            self.userInfoDict = object[@"data"];
            [self.tableView reloadData];
            
        }
       
        NSLog(@"%@",self.userInfoDict);
    }];
}

//用户是否登录
- (void)judgeUser
{
    //用户是否登录
    if (![JudgeUserLogInTool JudgeUserLonInStatus:self.view]) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"您尚未登录用户" message:nil preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *SettingAction = [UIAlertAction actionWithTitle:@"去登录" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            LogInViewController *accountVC = [[LogInViewController alloc] init];
            UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:accountVC];
            [self presentViewController:nav animated:YES completion:nil];
        }];
        [alert addAction:SettingAction];
        
        
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消"style:UIAlertActionStyleCancel handler:nil];
        [alert addAction:cancelAction];
        
        [self presentViewController:alert animated:YES completion:nil];
        return;
    }
}

@end
